home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 577 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.7 KB  |  78 lines

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: oliva@dcc.unicamp.br (Alexandre Oliva)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Semantics of "new foo[0]"
  5. Date: 28 Feb 1996 16:16:43 GMT
  6. Organization: DCC - UNICAMP - Campinas, SP, Brazil
  7. Sender: oliva@grande.dcc.unicamp.br
  8. Approved: clamage@eng.sun.com (comp.std.c++)
  9. Message-ID: <orag23j2kn.fsf@grande.dcc.unicamp.br>
  10. References: <MGB.96Feb27175316@kronecker.mitre.org>
  11. NNTP-Posting-Host: taumet.eng.sun.com
  12. Content-Type: text
  13. X-Nntp-Posting-Host: grande.dcc.unicamp.br
  14. In-Reply-To: mgb@kronecker.mitre.org's message of 27 Feb 1996 15:13:07 PST
  15. X-Newsreader: Gnus v5.1
  16. Content-Length: 1762
  17. X-Lines: 50
  18. Originator: clamage@taumet
  19.  
  20. The ARM is  out of date.  The September '95 DWP  (which is also out of
  21. date) states:
  22.  
  23.   3.7.3.1  Allocation functions           [basic.stc.dynamic.allocation]
  24.  
  25. 2 Each [...] allocation shall 
  26.   yield a pointer to storage (_intro.memory_) disjoint  from  any  other
  27.   currently allocated storage.  The pointer returned points to the start
  28.   (lowest byte address) of the allocated storage.  If the  size  of  the
  29.   space requested is zero, the value returned shall be nonzero and shall
  30.   not point to or within any other  currently  allocated  storage.   The
  31.   results of dereferencing a pointer returned as a request for zero size
  32.   are undefined.2)
  33.  
  34.   _________________________
  35.   2) The intent is to have operator new() implementable by calling  mal¡
  36.   loc()  or calloc(), so the rules are substantially the same.  C++ dif¡
  37.   fers from C in requiring a zero request to return a non-null  pointer.
  38.  
  39. G Mike Butler D054 writes:
  40.  
  41. > According to the ARM section 5.3.3:
  42. >      "operator new() can be called with the argument
  43. >       zero.  Repeated such calls return pointers to
  44. >       distinct objects."  
  45.       
  46. > But when I execute the following:
  47. >     #include <isotream.h>
  48. >     main()
  49. >     {
  50. >       struct foo { char a[1024]; };
  51. >       foo *p = new foo[0];
  52. >       foo *q = new foo[0];
  53.  
  54. >       cout << (void *)p << " " << (void *)q << endl;
  55. >     }
  56.  
  57. > I get
  58. >     0x338d8 0x338e8
  59.  
  60. > While these are distinct pointers, the pointers refer to overlapping
  61. > objects. Is this a legitimate interpretation of section 5.3.3 or is
  62. > this a compiler/library bug?
  63.  
  64. > Incidentally, the standard template library included with gcc 2.7.2
  65. > relies on "operator new(0)" working.
  66. -- 
  67. Alexandre Oliva
  68. oliva@dcc.unicamp.br
  69. Universidade Estadual de Campinas, S~ao Paulo, Brasil
  70.  
  71.  
  72. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your
  73.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  74.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  75.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  76.   Comments? mailto:std-c++-request@ncar.ucar.edu
  77. ]
  78.